package com.ruoyi.web.domain.warning;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.web.enums.InsectWarningTypeEnum;
import com.ruoyi.web.utils.v2.V2DeviceInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 虫情预警记录
 *
 * @author fwx
 * @since 2024-02-06 14:32:38
 */
@Data
@TableName("tt_warning_insect_record")
@ApiModel(value = "WarningInsectRecord对象", description = "虫情预警记录")
public class WarningInsectRecord implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("虫情预警类型 1 始见预警 2 日高峰 3 月高峰")
    @TableField("insect_warning_type")
    private Integer insectWarningType;

    @ApiModelProperty("预警时间")
    @TableField("warning_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime warningTime;

    @ApiModelProperty("预警值")
    @TableField("warning_value")
    private Integer warningValue;

    @ApiModelProperty("预警值")
    @TableField("warning_judge_value")
    private Integer warningJudgeValue;

    @ApiModelProperty("昆虫类型  1 一类害虫 2 二类害虫 3 其他")
    @TableField("insect_type")
    private Integer insectType;

    @ApiModelProperty("昆虫名字")
    @TableField("insect_name")
    private String insectName;

    @ApiModelProperty("昆虫编码")
    @TableField("insect_code")
    private String insectCode;

    @ApiModelProperty("设备名称")
    @TableField("device_name")
    private String deviceName;

    @ApiModelProperty("设备id")
    @TableField("device_id")
    private String deviceId;

    @ApiModelProperty("创建时间")
    @TableField("crt_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime crtTime;

    @ApiModelProperty("是否发送短信")
    @TableField("is_send_sms")
    private Integer isSendSms;

    @ApiModelProperty("是否发送邮件")
    @TableField("is_send_email")
    private Integer isSendEmail;

    @ApiModelProperty("是否查看")
    @TableField("is_click")
    private Integer isClick;

    @ApiModelProperty("设备信息")
    @TableField(exist = false)
    private V2DeviceInfo deviceInfo;

    public String buildEmailContent(){
        String warningTime = DateUtils.formatDateTime(this.warningTime);

        String format = null;
        if(Objects.equals(this.getInsectWarningType(),InsectWarningTypeEnum.FIRST.getValue())){
            format = String.format("[物联网平台] - 虫情始见告警,在%s发生,设备名:[%s](ID:[%s]),始见虫类[%s]",
                 warningTime,this.getDeviceName(),this.getDeviceId(),this.getInsectName());
        }else {
            String dm = Objects.equals(this.getInsectWarningType(),InsectWarningTypeEnum.DAY.getValue()) ? "日" : "月";
            String dmtype = Objects.equals(this.getInsectWarningType(),InsectWarningTypeEnum.DAY.getValue()) ? "日高峰" : "月高峰";

            format = String.format("[物联网平台] - %s告警,在%s发生,设备名:[%s](ID:[%s]),%s累计识别%s共[%d]只",
                    dmtype, warningTime,this.getDeviceName(),this.getDeviceId(),dm,this.getInsectName(),this.warningValue);
        }

        return format;
    }

}
